#pragma once
#include "common.h"
#include "singleton.h"
#include "basemanager.h"

class CDXUTDialog;
class CDXUTDialogResourceManager;
class CDXUTControl;

enum EDialogState
{
	eDlgState_Hide = 0,
	eDlgState_Show = 1,
};

enum EControlType
{
	eCtrl_Button = 0,
	eCtrl_Static = 1,
};

struct Control
{
	Control()
	{

	}
	int type;
	int id;
	char *text;
	int x;
	int y;
	int width;
	int height;
};

struct UIGadget
{
	UIGadget();
	~UIGadget();
	void Reset()
	{
		dlg = NULL;
		state = eDlgState_Hide;
		order = 0;
	}
	void AddControl( Control &ctrl );
	void SetPosition(  int x, int y );
	void SetSize( int width, int height );
    void SetBackground( LPWCH filename );
    void SetVisible( bool visible );
    void SetControlTexture( int controlid, LPWCH filename );
    void SetControlFont( int controlid, LPCWSTR strFaceName, int height, int weight, int color );
	CDXUTDialog *dlg;
	EDialogState state;
	int order;
	int dlgID;
};

typedef std::vector<int> GadgetQueue;
class UI:public CBaseObjContainer<int, UIGadget*>,public CSingleton<UI>
{
	IMPLEMENT_SINGLETON(UI);
public:
	void Init();
	void Update( int diff );
	void Render( int diff );
	void RenderUI( int id, float diff );
	UIGadget *CreateGadget( int id );
    UIGadget *GetGadget( int id )
    {
        return Find( id );
    }
	void Clear();
	bool MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
	static void __stdcall HandleEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );

private:
	CDXUTDialogResourceManager *m_pDlgManager;
	GadgetQueue m_dlgqueue;
};